home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 13653 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.1 KB

  1. Path: news.logicon.com!newsmaster@klee
  2. From: kkolda@logicon.com (Kenneth D. Kolda)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: static members of a class template
  5. Date: 26 Mar 1996 17:35:56 GMT
  6. Organization: Logicon Operating Systems
  7. Message-ID: <4j99ts$num@piper.logicon.com>
  8. References: <315781CB.2DD1@digex.net>
  9. NNTP-Posting-Host: 137.51.122.161
  10. Mime-Version: 1.0
  11. X-Newsreader: WinVN 0.99.2
  12.  
  13. In article <315781CB.2DD1@digex.net>, yami@digex.net says...
  14. >
  15. >Hi,
  16. >
  17. >How would you go about declaring a static member of a class template?  
  18. >Example:
  19. >
  20. >template<class kind>
  21. >class simple {
  22. >    private:
  23. >        static kind someVar;
  24. >};
  25. >
  26. >simple<kind> kind simple::someVar;
  27. >
  28. >
  29. >This seems to follow the general pattern for defining and declaring a 
  30. >static member, but it results in a syntax error.  What's the problem?
  31. >
  32. >Thanks in advance for any advice!
  33. >
  34. >-Steve-
  35.  
  36.  
  37. I think what you want is as follows:
  38.  
  39. template simple<class kind> kind simple<kind>::someVar;
  40.  
  41. where you could also add initialization info if desired.  You can then 
  42. override this default initialization, for example, for simple<int> with:
  43.  
  44. int simple<int>::someVar = 2;
  45.  
  46.  
  47. Ken
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.